<template>
	<view class="content">
		<view class="header">
			<image src="../../static/shilu-login/logo.png"></image>
		</view>

		<view class="list">
			<view class="list-call">
				<image class="img" src="/static/shilu-login/1.png"></image>
				<input class="sl-input" v-model="phone" type="number" maxlength="11" placeholder="手机号" />
			</view>
			<view class="list-call">
				<image class="img" src="/static/shilu-login/2.png"></image>
				<input class="sl-input" v-model="password" type="text" maxlength="32" placeholder="登录密码"
					:password="isShowPassword" />
				<image class="img" :src="isShowPassword ? '/static/shilu-login/op.png' : '/static/shilu-login/cl.png'"
					@tap="display"></image>
			</view>
			<view class="list-call">
				<image class="img" src="/static/shilu-login/3.png"></image>
				<input class="sl-input" v-model="code" type="number" maxlength="4" placeholder="验证码" />
				<view class="yzm" :class="{ yzms: second > 0 }" @tap="getcode">{{ yanzhengma }}</view>
			</view>
			<view class="list-call">
				<image class="img" src="/static/shilu-login/4.png"></image>
				<input class="sl-input" v-model="invitation" type="text" maxlength="12" placeholder="邀请码" />
			</view>
		</view>

		<view class="button-login" hover-class="button-hover" @tap="bindLogin">
			<text>注册</text>
		</view>

		<view class="agreement">
			<image :src="agreement ? '/static/shilu-login/ty1.png' : '/static/shilu-login/ty0.png'"
				@tap="agreementSuccess"></image>
			<text @tap="agreementSuccess">同意</text>
			<navigator url="agreement?id=1" open-type="navigate">《软件用户协议》</navigator>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				phone: '',
				password: '',
				code: '',
				invitation: '',
				agreement: true,
				showPassword: false,
				second: 0,
				js: null
			};
		},
		computed: {
			yanzhengma() {
				if (this.second === 0) {
					return '获取验证码';
				} else {
					if (this.second < 10) {
						return '重新获取0' + this.second;
					} else {
						return '重新获取' + this.second;
					}
				}
			}
		},
		methods: {
			clear() {
				clearInterval(this.js);
				this.js = null;
				this.second = 0;
			},
			display() {
				this.showPassword = !this.showPassword;
			},
			agreementSuccess() {
				this.agreement = !this.agreement;
			},
			getcode() {
				if (this.phone.length !== 11) {
					uni.showToast({
						icon: 'none',
						title: '手机号不正确'
					});
					return;
				}
				if (this.second > 0) {
					return;
				}

				// 发送验证码请求的逻辑
				// ...

				// 开始倒计时
				this.second = 60;
				this.js = setInterval(() => {
					if (this.second > 0) {
						this.second--;
					} else {
						this.clear();
					}
				}, 1000);
			},
			bindLogin() {
				// 登录逻辑
				// ...
			}
		},
		onLoad() {
			this._this = this;
		},
		onUnload() {
			this.clear();
		}
	};
</script>